<template>
  <div>
    <el-table stripe style="width: 100%;font-size: 11px" :data="tableData">
      <el-table-column prop="topic" label="主题"></el-table-column>
      <el-table-column prop="host" label="主办人"></el-table-column>
      <el-table-column prop="startDate" label="开始日期"></el-table-column>
      <el-table-column prop="endDate" label="结束日期"></el-table-column>
      <el-table-column prop="details" label="详细"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="update1(scope.row)" icon="el-icon-edit" circle></el-button>
          <el-button type="primary" icon="el-icon-delete" circle @click="open(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="研发计划" :visible.sync="dialogFormVisible">
      <el-form >
        <el-form-item label="主题" :label-width="formLabelWidth">
          <el-input v-model="form.topic" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="主办人" :label-width="formLabelWidth">
          <el-input v-model="form.host" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="开始日期" :label-width="formLabelWidth">
          <el-input v-model="form.startDate" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="结束日期" :label-width="formLabelWidth">
          <el-input v-model="form.endDate" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="详细" :label-width="formLabelWidth">
          <el-input v-model="form.details" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="updataxx" >确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { selectplan, delPlan,updateplan } from '../../../api/research';

export default {
  mounted() {
   this.selplan();

  },
  data() {
    return {
      form: {
        planId: '',
        topic: '',
        host:'',
        startDate:'',
        endDate: '',
        details: '',
      },

      tableData: [],
      dialogFormVisible: false,
      formLabelWidth: '100px',

    };
  },

  methods: {
    selplan(){
      selectplan().then(res=>{
        console.log(res);
        this.tableData=res.result;
      })
    },
    update1(row){
      this.form.planId=row.planId;
      this.form.topic=row.topic;
      this.form.host=row.host;
      this.form.startDate=row.startDate;
      this.form.endDate=row.endDate;
      this.form.details=row.details;
      this.dialogFormVisible = true;
    },
    updataxx(){
      this.dialogFormVisible = false;
      updateplan( this.form.planId,
                  this.form.topic,
                  this.form.host,
                  this.form.startDate,
                  this.form.endDate,
                  this.form.details,).then(res=>{
        console.log(res);
        if (res.code == 200) {
          this.selplan();
              this.$message.success(res.message)
            } else {
              this.$message.error(res.message)
            }
          this.dialogFormVisible = false;

      })
    },
    open(row) {
      let id = row.planId;
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delPlan(id).then(res=>{
            console.log(res);

          })
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      }

},
}
</script>

<style>
/* Add your styles here */
</style>
